using System;
using System.Collections.Generic;
using System.Text;
using XinBang.Entity;
using XinBang.DAL;
using XinBang.DAL.NHibernate;

namespace XinBang.BLL
{
    public class ArticleBL
    {
        IArticleDA<Article> ad = BusinessLogicFactory.GetArticleDA();

        public Article GetArticleById(int p)
        {
            return ad.Get(p);
        }

        public void UpdateArticle(Article art)
        {
            ad.Update(art);
        }

        public void InsertArticle(Article art)
        {
            ad.Insert(art);
        }

        public IList<Article> GetTopNArticlesByCatid(string catid, int size)
        {
            return ad.GetTopNArticlesByCatid(Convert.ToInt32(catid), size);
        }

        public void DeleteArticle(Article art)
        {
            ad.Delete(art);
        }

        public int GetArticlesCountByCatid(int p)
        {
            return GetAllArticlesByCatid(p).Count;
        }

        public IList<Article> GetAllArticlesByCatid(int catid)
        {
            return ad.GetAllArticlesByCatid(catid);
            //string key = string.Concat("ArticleBL.GetAllArticleByCatid.", catid);
            //IList<Article> list = (IList<Article>)cache.GetData(key);
            //if (list==null)
            //{
            //    cache.Add(key, ad.GetAllArticlesByCatid(catid), CacheItemPriority.Normal,null,new SlidingTime(TimeSpan.FromMinutes(30)));//,new SqlDependencyExpiration("Shyvo_Article"));
            //    list = (IList<Article>)cache.GetData(key);
            //}
            //return list;
        }

        public void AddVisitCount(Article a)
        {
            a.Hits += 1;
            ad.Update(a);
        }

        public IList<Article> GetArticlesByCatidSizePage(int catid, int size, int page)
        {
            return ad.GetArticlesListByCatidSizePage(catid, size, page);
        }
    }
}